<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./lib/vue-2.5.9.js"></script>
</head>

<body>
  <div id="app">

    <a href="#/a">a</a>
    <a href="#/b">b</a>
    <a href="#/c">c</a>

    <component :is="comname"></component>

  </div>

  <script>

    Vue.component('com1', {
      template: '<h3>a组件</h3>'
    })

    Vue.component('com2', {
      template: '<h3>b组件</h3>'
    })

    Vue.component('com3', {
      template: '<h3>c组件</h3>'
    })

    // 创建 Vue 实例，得到 ViewModel
    var vm = new Vue({
      el: '#app',
      data: {
        comname: 'com1'
      },
      methods: {},
      mounted() { // 当页面被渲染出来之后，做一些事情
        window.onhashchange = () => {
          // 获取到 URL中的 hash 地址
          const hash = location.hash
          // console.log(hash)
          switch (hash) {
            case '#/a':
              this.comname = 'com1'
              break;
            case '#/b':
              this.comname = 'com2'
              break;
            case '#/c':
              this.comname = 'com3'
              break;
          }
        }
      }
    });


  </script>
</body>

</html>